<?php

namespace Apipad\Controller;

use Think\Controller;

//产品订单中心
header("content-type:application/json;charset=utf-8");

class OrderController extends CommonController
{

    //获取草稿箱ID
    public function getOrder_last()
    {
        $uid = UID;
        $detail = I('post.');
        $model_user_order = M("user_order");
        $where['uid'] = $uid;
        $where['isdel'] = 0;
        $where['status'] = 0;
        $info = $model_user_order->where($where)->order('id asc')->find();
        if (empty($info)) {
            $data_cc['code'] = 200;
            $data_cc['msg'] = "查询成功";
            $data['data']['info'] = [];
            exit(json_encode($data_cc));
        }
        $info['dqvalue'] = json_decode($info['dqvalue'], true);
        $data['code'] = 200;
        $data['msg'] = '查询成功';
        $data['data']['info'] = $info;
        exit(json_encode($data));
    }

    public function add_order()
    {
        $uid = UID;
        $model_user_order = M("user_order");
        $detail = I('post.', '', 'strip_tags');
        $id = trim($detail['id']);
        $customer_name = trim($detail['customer_name']);
        $company = trim($detail['company']);
        $mobile = trim($detail['mobile']);
        $address = trim($detail['address']);
        $goods_number = trim($detail['goods_number']);
        $amount = trim($detail['amount']);
        $payment_amount = trim($detail['payment_amount']);
        $mobile = trim($detail['mobile']);
        $remark = trim($detail['remark']);
        if (empty($customer_name)) {
            $data['code'] = 0;
            $data['msg'] = '请输入客户名称';
            exit(json_encode($data));
        }
        if (empty($mobile)) {
            $data['code'] = 0;
            $data['msg'] = '请输入联系方式';
            exit(json_encode($data));
        }

        $data['uid'] = $uid;
        //查询订单数
        $countc = $model_user_order->where(['uid' => $uid, 'isdel' => 0])->count();
        $cocda = $countc + 1;
        $data['ordersn'] = 'MDK8000' . $uid . $cocda;
        $data['customer_name'] = $customer_name;
        $data['mobile'] = $mobile;
        $data['address'] = $address;
        $data['dqvalue'] = json_encode($detail['dqvalue']);
        $data['region'] = $detail['region'];
        $data['goods_number'] = $goods_number;
        $data['amount'] = $amount;
        $data['payment_amount'] = $payment_amount;
        $data['company'] = $company;
        $data['remark'] = $remark;
        $data['stype'] = 0;
        $data['add_time'] = time();
        if ($id) {
            $result = $model_user_order->where(['uid' => $uid, 'id' => $id])->save($data);
            $msg = "编辑";
        } else {
            $result = $model_user_order->add($data);
            $msg = "添加";
        }
        if ($result) {
            $data_cc['code'] = 200;
            $data_cc['msg'] = $msg . "成功";
            $data_cc['data'] = $result;
            exit(json_encode($data_cc));
        } else {
            $data_cc['code'] = 0;
            $data_cc['msg'] = $msg . "失败";
            exit(json_encode($data_cc));
        }
    }

    public function order_detail()
    {
        $uid = UID;
        $detail = I('post.');
        $model_user_order = M("user_order");
        $id = $detail['id'];
        if (empty($id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "参数错误";
            exit(json_encode($data_cc));
        }
        $where['uid'] = $uid;
        $where['id'] = $id;
        $info = $model_user_order->where($where)->find();
        if (empty($info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "信息查询失败";
            exit(json_encode($data_cc));
        }
        $data['code'] = 200;
        $data['msg'] = '查询成功';
        $data['info'] = $info;
        exit(json_encode($data));
    }

    //删除订单
    public function order_del()
    {
        $detail = I('post.');
        $uid = UID;
        $id = $detail["id"];
        if (empty($id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "参数错误";
            exit(json_encode($data_cc));
        }
        $model_user_order = M("user_order");
        $where['uid'] = $uid;
        $where['id'] = $id;
        $where['isdel'] = 0;
        $info = $model_user_order->where($where)->find();
        if ($info) {
            $this->delt($id);
            $data_cc['code'] = 200;
            $data_cc['msg'] = "删除成功";
            exit(json_encode($data_cc));
        } else {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "该订单信息不存在";
            exit(json_encode($data_cc));
        }
    }

    //款式列表
    public function order_list()
    {
        $detail = I('post.');
        $user_order = M("user_order");
        $page = $detail['page'] ? $detail['page'] : 1;
        $limit = $detail['limit'] ? $detail['limit'] : 15;
        $kewords = $detail['kewords'];
        $times = $detail['times'];
        if ($times) {
            $stime = explode(',', $times);
            $datatime1 = strtotime($stime[0]);
            $datatime2 = strtotime($stime[1]);
            $where['add_time'] = ['gte', $datatime1];
            $where['add_time'] = ['lt', $datatime2];
        }
        $uid = UID;
        $where['isdel'] = 0;
        $where['uid'] = $uid;
        $where['status'] = 1;
        if ($kewords) {
            $where['customer_name|mobile|address|ordersn'] = ['like', '%' . $kewords . '%'];
        }
        $count = $user_order->where($where)->count();
        $list = $user_order
            ->where($where)
            ->order('id desc')->page($page, $limit)->select();
        foreach ($list as $k => $v){
            $list[$k]['add_time'] = date('Y-m-d H:i:s', $list[$k]['add_time']);
        }
        $data_cc['code'] = 200;
        $data_cc['msg'] = '查询成功';
        $data_cc['count'] = $count;
        $data_cc['list'] = $list;
        exit(json_encode($data_cc));
    }

    //款式列表
    public function goods_list()
    {
        $detail = I('post.');
        $model_user_goods = M("user_goods");
        $page = $detail['page'] ? $detail['page'] : 1;
        $limit = $detail['limit'] ? $detail['limit'] : 15;
        $kewords = $detail['kewords'];
        $cate_id = $detail['cate_id'];
        $uid = UID;
        $where['isdel'] = 0;
        $where['uid'] = $uid;
        if ($cate_id) {
            $dsf = $this->get_child($cate_id, 0);
            $where['cate_id'] = ['in', $dsf];
        }
        if ($kewords) {
            $where['goods_name|goods_sn|goods_attr'] = ['like', '%' . $kewords . '%'];
        }

        $count = $model_user_goods->where($where)->count();

        $list = $model_user_goods
            ->where($where)
            ->order('id desc')->page($page, $limit)->select();

        $data_cc['code'] = 200;
        $data_cc['msg'] = '查询成功';
        $data_cc['count'] = $count;
        $data_cc['list'] = $list;
        exit(json_encode($data_cc));
    }

    //加入购物车
    public function add_cart()
    {
        $detail = I('post.');
        $uid = UID;
        $goods_id = $detail["goods_id"];
        $order_id = $detail["order_id"];
        $type = $detail["type"] ?: 0;
        $user_cart = M("user_cart");
        $whet['uid'] = $uid;
        $whet['goods_id'] = $goods_id;
        $whet['order_id'] = $order_id;
        $whet['isdel'] = 0;
        $whet['stype'] = $type;
        $model_user_goods = M("user_goods");
        if ($type == 1) {
            $model_user_goods = M("img");
            $where['is_delete'] = 0;
            $where['id'] = $goods_id;
        } else {
            $where['isdel'] = 0;
            $where['id'] = $goods_id;
        }

        $count = $model_user_goods->where($where)->count();
        if ($count == 0) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "该商品信息查询失败";
            exit(json_encode($data_cc));
        }
        $info = $user_cart->where($whet)->find();
        $data['uid'] = $uid;
        $data['goods_id'] = $goods_id;
        $data['stype'] = $type;
        $data['order_id'] = $order_id;
        $data['add_time'] = time();
        if (empty($info)) {
            $user_cart->add($data);
        }
        $data_cc['code'] = 200;
        $data_cc['msg'] = "加入成功";
        exit(json_encode($data_cc));
    }

    //删除购物车
    public function del_cart()
    {
        $detail = I('post.');
        $uid = UID;
        $cart_id = $detail["cart_id"];
        $order_id = $detail["order_id"];
        $type = $detail["type"] ?: 0;
        $stype = $detail["stype"] ?: 0;
        $user_cart = M("user_cart");
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "order_id参数错误";
            exit(json_encode($data_cc));
        }
        $where['uid'] = $uid;
        $where['stype'] = $type;
        $where['order_id'] = $order_id;
        if ($stype == 0) {
            if (empty($cart_id)) {
                $data_cc['code'] = 0;
                $data_cc['msg'] = "cart_id参数错误";
                exit(json_encode($data_cc));
            }
            $where['id'] = $cart_id;
            $msg = "删除";
        } else {
            $msg = "操作";
        }
        $list = $user_cart->where($where)->select();
        if ($list) {
            $mt = 0;
            foreach ($list as $k => $val) {
                $user_cart->where(['id' => $val['id']])->save(['isdel' => 1, 'del_time' => time()]);
                $mt = 1;
            }
            if ($mt) {
                $data_cc['code'] = 200;
                $data_cc['msg'] = $msg . "成功";
                exit(json_encode($data_cc));
            } else {
                $data_cc['code'] = 0;
                $data_cc['msg'] = $msg . "失败";
                exit(json_encode($data_cc));
            }
        } else {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "该信息不存在";
            exit(json_encode($data_cc));
        }
    }

    //购物车列表
    public function cart_list()
    {
        $detail = I('post.');
        $uid = UID;
        $user_cart = M("user_cart");
        $kewords = $detail['kewords'];
        $order_id = $detail["order_id"];
        $type = $detail["type"] ?: 0;
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "order_id参数错误";
            exit(json_encode($data_cc));
        }

        $where['ct.isdel'] = 0;
        $where['ct.uid'] = $uid;
        $where['ct.order_id'] = $order_id;
        $where['ct.stype'] = $type;
        if ($type == 1) {
            if ($kewords) {
                $where['t.title'] = ['like', '%' . $kewords . '%'];
            }
            $list = $user_cart->alias('ct')->join('left join fa_renshi_img AS t ON t.id=ct.goods_id')->where($where)
                ->order('ct.id desc')
                ->field('ct.id,ct.goods_id,t.title as goods_name,t.img as goods_img')
                ->select();
        } else {
            if ($kewords) {
                $where['g.goods_name|g.goods_sn|g.goods_attr'] = ['like', '%' . $kewords . '%'];
            }
            $list = $user_cart->alias('ct')->join('left join fa_renshi_user_goods AS g ON g.id=ct.goods_id')->where($where)
                ->order('ct.id desc')
                ->field('ct.id,ct.goods_id,g.goods_name,g.goods_sn,g.chenfen,g.goods_img')
                ->select();
        }
        $data_cc['code'] = 200;
        $data_cc['msg'] = '查询成功';
        $data_cc['list'] = $list;
        exit(json_encode($data_cc));
    }

    //工艺部件列表
    public function technology_list()
    {
        $detail = I('post.');
        $img = M("img");
        $page = $detail['page'] ? $detail['page'] : 1;
        $limit = $detail['limit'] ? $detail['limit'] : 15;
        $kewords = $detail['kewords'];
        $cate_id = $detail['cate_id'];
        $uid = UID;
        $where['is_delete'] = 0;
        $where['status'] = 0;
        if ($cate_id) {
            $dsf = $this->get_childcc($cate_id, 0);
            $where['pid'] = ['in', $dsf];
        }
        if ($kewords) {
            $where['title'] = ['like', '%' . $kewords . '%'];
        }
        $count = $img->where($where)->count();
        $list = $img
            ->where($where)
            ->order('id desc')->page($page, $limit)->field('id,title,img')->select();
        $data_cc['code'] = 200;
        $data_cc['msg'] = '查询成功';
        $data_cc['count'] = $count;
        $data_cc['list'] = $list;
        exit(json_encode($data_cc));
    }

    //根据性别 身高 体重  品类查询信息
    public function get_mysqlcc()
    {
        $detail = I('post.');
        $user_mysql_list = M("user_mysql_list");
        $user_mysql_listc = M("user_mysql_listc");
        $sex = $detail['sex'] ?: 1;
        $high = $detail['high'] ?: '';
        $cate_id = $detail['cate_id'] ?: 0;
        $weight = $detail['weight'] ?: '';
        if (empty($high)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请输入身高";
            exit(json_encode($data_cc));
        }
        if (empty($cate_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "cate_id参数错误";
            exit(json_encode($data_cc));
        }
        //根据大类ID 查询上衣或者裤子
        $user_mysql_cate = M("user_mysql_default_cate");

        $mysql_child_count = $user_mysql_cate->where(['pid' => $cate_id, 'isdel' => 0])->count();
        $uid = UID;
        if ($mysql_child_count > 0) {
            $cate_id2 = $cate_id1 = 0;
            if ($cate_id) {
                $cate_id1 = $user_mysql_cate->where(['pid' => $cate_id, 'stype' => 1, 'sht_c' => 0, 'isdel' => 0])->getField('id');
                $cate_id2 = $user_mysql_cate->where(['pid' => $cate_id, 'stype' => 1, 'sht_c' => 1, 'isdel' => 0])->getField('id');
            }
            //weight
            $jo_res = $weight % 2;
            if ($jo_res != 0) {
                $weight = bcadd($weight, 1);
            }
            //衣服
            $where['isdel'] = 0;
            $where['uid'] = $uid;
            $where['sex'] = $sex;
            $where['high'] = $high;
            $where['cat_id'] = $cate_id1;
            $where['weight'] = $weight;
            //裤子 
            $fyst['isdel'] = 0;
            $fyst['uid'] = $uid;
            $fyst['sex'] = $sex;
            $fyst['high'] = $high;
            $fyst['cat_id'] = $cate_id2;
            $fyst['weight'] = $weight;
            $result['shagnyi_info'] = $user_mysql_list->where($where)->find();
            $result['kuzi_info'] = $user_mysql_listc->where($fyst)->find();
        } else {
            $cate_info = $user_mysql_cate->where(['id' => $cate_id, 'stype' => 1, 'isdel' => 0])->find();
            if ($cate_info['sht_c'] == 1) {
                //下装
                $fyst['isdel'] = 0;
                $fyst['uid'] = $uid;
                $fyst['sex'] = $sex;
                $fyst['high'] = $high;
                $fyst['cat_id'] = $cate_id;
                $fyst['weight'] = $weight;
                $result['kuzi_info'] = $user_mysql_listc->where($fyst)->find();
                $result['shagnyi_info'] = [];
            } else {
                //上装
                $where['isdel'] = 0;
                $where['uid'] = $uid;
                $where['sex'] = $sex;
                $where['high'] = $high;
                $where['cat_id'] = $cate_id;
                $where['weight'] = $weight;
                $result['kuzi_info'] = [];
                $result['shagnyi_info'] = $user_mysql_list->where($where)->find();
            }
        }
        $data_cc['code'] = 200;
        $data_cc['msg'] = '查询成功';
        $data_cc['info'] = $result;
        exit(json_encode($data_cc));
    }

    //品类选择列表
    public function getCate()
    {
        $uid = UID;
        $user_mysql_cate = M("user_mysql_default_cate");
        $list = $user_mysql_cate->where(['pid' => 0, 'stype' => 2, 'uid' => $uid])->field('id,title')->order('id asc')->select();
        $data_cc['code'] = 200;
        $data_cc['msg'] = '查询成功';
        $data_cc['list'] = $list;
        exit(json_encode($data_cc));
    }
    //品类尺寸列表
    // public function cate_desgin(){
    //     $cate_id = I('cate_id');
    //     if(empty($cate_id)){
    //         $data_cc['code']=0;
    //         $data_cc['msg']='品类ID不能为空';
    //         exit(json_encode($data_cc));
    //     }
    //     $user_mysql_cate=M("user_mysql_cate");
    //     $info = $user_mysql_cate->where(['id'=>$cate_id,'uid'=>UID,'stype'=>2,'isdel'=>0])->find();
    //     if(empty($info)){
    //         $data_cc['code']=0;
    //         $data_cc['msg']='品类信息不存在';
    //         exit(json_encode($data_cc));
    //     }
    //     $user_mysql_list=M("user_mysql_list"); 
    //     $user_mysql_listc=M("user_mysql_listc"); 
    //     $cate_upper=$user_mysql_cate->where(['pid'=>$cate_id,'stype'=>2,'uid'=>UID,'sht_c'=>0,'isdel'=>0])->select();
    //     $cate_upper_str = '';
    //     foreach($cate_upper as $k=>$v){
    //         if($cate_upper_str == ''){
    //             $cate_upper_str =  $cate_upper_str.$v['id'];
    //         }else{
    //             $cate_upper_str =  $cate_upper_str.','.$v['id'];
    //         }
    //     }
    //     $cate_below=$user_mysql_cate->where(['pid'=>$cate_id,'stype'=>2,'uid'=>UID,'sht_c'=>1,'isdel'=>0])->select();
    //     $cate_below_str = '';
    //     foreach($cate_below as $bk=>$bv){
    //         if($cate_below_str == ''){
    //             $cate_below_str =  $cate_below_str.$bv['id'];
    //         }else{
    //             $cate_below_str =  $cate_below_str.','.$bv['id'];
    //         }
    //     }
    //     $uid=UID;
    //     //衣服
    //     $where['isdel']=0;
    //     $where['uid']=$uid;
    //     $where['_string']='FIND_IN_SET(cat_id,"'.$cate_upper_str.'")';
    //     //裤子
    //     $fyst['isdel']=0;
    //     $fyst['uid']=$uid;
    //     $fyst['_string']='FIND_IN_SET(cat_id,"'.$cate_below_str.'")';
    //     $cate_upper_list=$user_mysql_list->where($where)->select();
    //     $cate_below_list=$user_mysql_listc->where($fyst)->select();
    //     $data_cc['code']=200;
    //     $data_cc['msg']='查询成功';
    //     $data_cc['upper_list']=$cate_upper_list;
    //     $data_cc['below_list']=$cate_below_list;
    //     exit(json_encode($data_cc));
    // }

    //生成推荐数据
    public function recommend_data()
    {
        $detail = I('');
        $upper_id = $detail['upper_id'];
        $below_id = $detail['below_id'];
        $user_mysql_list = M("user_mysql_list");
        $user_mysql_listc = M("user_mysql_listc");
        $uid = UID;
        //衣服
        $where['isdel'] = 0;
        $where['uid'] = $uid;
        $where['id'] = $upper_id;
        //裤子
        $fyst['isdel'] = 0;
        $fyst['uid'] = $uid;
        $fyst['id'] = $below_id;
        $cate_upper_list = $user_mysql_list->where($where)->find();
        $cate_below_list = $user_mysql_listc->where($fyst)->find();
        $data_cc['code'] = 200;
        $data_cc['msg'] = '查询成功';
        $data_cc['upper_list'] = $cate_upper_list;
        $data_cc['below_list'] = $cate_below_list;
        exit(json_encode($data_cc));
    }

    //新建量体部位列表
    public function litibuwei()
    {
        // $list['']
        $list[] = ['name' => '领围', 'key' => 'lw'];
        $list[] = ['name' => '前衣长', 'key' => 'qiancyi'];
        $list[] = ['name' => '后衣长', 'key' => 'hzhc'];
        $list[] = ['name' => '肩宽', 'key' => 'jiankuan'];
        $list[] = ['name' => '左袖长', 'key' => 'xiuchang'];
        $list[] = ['name' => '左袖长', 'key' => 'xiuchang'];
        $list[] = ['name' => '胸围', 'key' => 'cyxw'];
        $list[] = ['name' => '中腰', 'key' => 'zhonyao'];
        $list[] = ['name' => '肚围', 'key' => 'dw'];
        $list[] = ['name' => '臀围', 'key' => 'cptunwei'];
        $list[] = ['name' => '上臂围', 'key' => 'sbw'];
        $list[] = ['name' => '小臂围', 'key' => 'xbw'];
        $list[] = ['name' => '袖口围', 'key' => 'xkw'];
        $list[] = ['name' => '袖夹围', 'key' => 'xjw'];
        $list[] = ['name' => '前胸宽', 'key' => 'qxk'];
        $list[] = ['name' => '后背宽', 'key' => 'hbk'];
        $list[] = ['name' => '肚高点', 'key' => 'dgd'];
        $list[] = ['name' => '（女）胸高点', 'key' => 'nxgd'];
        $list[] = ['name' => '（女）胸距离', 'key' => 'nxjl'];
        $list[] = ['name' => '前腰节', 'key' => 'qyj'];
        $list[] = ['name' => '后腰节', 'key' => 'hyj'];
        $list[] = ['name' => '裤/裙腰围', 'key' => 'qkyw'];
        $list[] = ['name' => '横档', 'key' => 'hd'];
        $list[] = ['name' => '膝围', 'key' => 'qw'];
        $list[] = ['name' => '小腿围', 'key' => 'xtw'];
        $list[] = ['name' => '脚口', 'key' => 'jiaokou'];
        $list[] = ['name' => '立档含腰', 'key' => 'ldhy'];
        $list[] = ['name' => '全档含腰', 'key' => 'qdhy'];
        $list[] = ['name' => '裤/裙长度', 'key' => 'kuchang'];
        $list[] = ['name' => '马甲前衣长', 'key' => 'mjqyc'];
        $list[] = ['name' => '马甲后衣长', 'key' => 'mjhyc'];
        $list[] = ['name' => '马甲胸围', 'key' => 'mjxw'];
        // $list=['领围','前衣长','后衣长','肩宽','右袖长','左袖长','胸围','中腰','肚围','臀围','上臂围','小臂围','袖口围','袖夹围','前胸宽','后背宽','肚高点','（女）胸高点','（女）胸距离','前腰节','后腰节','裤/裙腰围','横档','膝围','小腿围','脚口','立档含腰','全档含腰','裤/裙长度','马甲前衣长','马甲后衣长','马甲胸围']; 
        $data_cc['code'] = 200;
        $data_cc['msg'] = '查询成功';
        $data_cc['list'] = $list;
        exit(json_encode($data_cc));
    }

    //保存私人定制信息
    public function save_info()
    {
        $user_mysql_list = M("user_mysql_list");
        $user_mysql_listc = M("user_mysql_listc");
        $detail = I('post.');
        $uid = UID;
        $order_id = $detail['order_id'] ?: 0;
        $minf_c = $detail['minf_c'] ?: [];
        //$customer=$detail['customer']?:[];
        $customer = $detail;
        if (empty($customer['customer_name'])) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请输入顾客姓名";
            exit(json_encode($data_cc));
        }
        if (empty($customer['high'])) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请输入身高";
            exit(json_encode($data_cc));
        }
        if (empty($customer['weight'])) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请输入体重";
            exit(json_encode($data_cc));
        }
        if (empty($customer['cat_id'])) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请选择品类";
            exit(json_encode($data_cc));
        }
        if (empty($customer['upper_id'])) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请传递上衣尺寸ID";
            exit(json_encode($data_cc));
        }
        $info = $detail['info'] ?: [];
        $tstx = $detail['tstx'] ?: [];
        $picc = $detail['picc'] ?: '';
        $mt_data['uid'] = $uid;
        $mt_data['order_id'] = $order_id;
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "order_id参数错误";
            exit(json_encode($data_cc));
        }
        if (empty($info)) {
            //$data_cc['code'] = 0;
            //$data_cc['msg'] = "试衣备注参数错误";
            //exit(json_encode($data_cc));
        }
        $this->add_customercc($customer, $mt_data);
        $this->add_tuanti($detail, $mt_data);
        $this->add_sybz($detail, $mt_data);
        $this->add_tstx($detail, $mt_data);
        $this->add_txphote($picc, $mt_data);
        $data_cc['code'] = 200;
        $data_cc['msg'] = "操作成功";
        exit(json_encode($data_cc));
    }


    //顾客信息新增
    function add_customercc($info, $mt_data)
    {
        $data['customer_name'] = $info['customer_name'];
        $data['sex'] = $info['sex'];
        $data['age'] = $info['age'];
        $data['high'] = $info['high'];
        $data['weight'] = $info['weight'];
        $data['cat_id'] = $info['cat_id'];
        $data['upper_id'] = $info['upper_id'];
        $data['below_id'] = $info['below_id'];
        $data['order_id'] = $mt_data['order_id'];
        $data['uid'] = $uid = $mt_data['uid'];
        $user_private_customer = M("user_private_customer");
        $count = $user_private_customer->where(['uid' => $uid, 'order_id' => $mt_data['order_id'], 'customer_name' => $info['customer_name'], 'isdel' => 0])->count();
        if ($count) {
            $user_private_customer->where(['uid' => $uid, 'order_id' => $mt_data['order_id']])->save($data);
        } else {
            $data['add_time'] = time();
            $user_private_customer->add($data);
        }
    }

    //获取特殊体型列表
    public function get_tstxlist()
    {
        $imgcate = M("imgcate");
        $uid = UID;
        $list = $imgcate->where(['pid' => 0, 'status' => 4, 'is_delete' => 0])->field('id,title')->order('id asc')->select();
        if ($list) {
            foreach ($list as $k => $val) {
                $list[$k]['list'] = $this->get_childs($val['id']);
            }
        }
        $data_cc['code'] = 200;
        $data_cc['msg'] = '查询成功';
        $data_cc['list'] = $list;
        exit(json_encode($data_cc));
    }

    //获取私人定制信息列表信息
    public function sget_srdz_info()
    {
        $detail = I('post.');
        $uid = UID;
        $order_id = $detail['order_id'] ?: 0;
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "order_id参数错误";
            exit(json_encode($data_cc));
        }
        $where['uid'] = $uid;
        $where['id'] = $order_id;
        $model_user_order = M("user_order");
        $info = $model_user_order->where($where)->find();
        if (empty($info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "信息查询失败";
            exit(json_encode($data_cc));
        }
        $result['order_info'] = $info;
        $result['info'] = $this->customer_info($order_id);
        $data_cc['code'] = 200;
        $data_cc['msg'] = '查询成功';
        $data_cc['data'] = $result;
        exit(json_encode($data_cc));
    }

    //清空私人定制
    public function clear()
    {
        $detail = I('post.');
        $uid = UID;
        $order_id = $detail['order_id'] ?: 0;
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "order_id参数错误";
            exit(json_encode($data_cc));
        }
        $where['uid'] = $uid;
        $where['id'] = $order_id;
        $model_user_order = M("user_order");
        $info = $model_user_order->where($where)->find();
        if (empty($info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "信息查询失败";
            exit(json_encode($data_cc));
        }
        //清空对应的数据
        $this->cleart($order_id);
        $result['order_info'] = $info;
        $result['info'] = $this->customer_info($order_id);
        $data['code'] = 200;
        $data['msg'] = '操作成功';
        //$data['data'] = $result;
        exit(json_encode($data));
    }

    //查询体型下的图片信息
    public function get_childs($pid)
    {
        $img = M("img");
        $list = $img->where(['pid' => $pid, 'status' => 4, 'is_delete' => 0])->field('id,title,img')->order('id asc')->select();
        return $list;
    }

    //团体定制 添加公司
    public function add_company()
    {
        $detail = I('post.');
        $uid = UID;
        $order_id = $detail['order_id'] ?: 0;
        $company = $detail['company'] ?: '';
        $names = $detail['names'] ?: '';
        $mobile = $detail['mobile'] ?: '';
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "order_id参数错误";
            exit(json_encode($data_cc));
        }
        $where['uid'] = $uid;
        $where['id'] = $order_id;
        $model_user_order = M("user_order");
        $info = $model_user_order->where($where)->find();
        if (empty($info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "信息查询失败";
            exit(json_encode($data_cc));
        }
        if (empty($company)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请输入公司名称";
            exit(json_encode($data_cc));
        }
        if (empty($names)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请输入姓名";
            exit(json_encode($data_cc));
        }
        if (empty($mobile)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请输入手机号码";
            exit(json_encode($data_cc));
        }
        $data['uid'] = $uid;
        $data['order_id'] = $order_id;
        $data['company'] = $company;
        $data['names'] = $names;
        $data['mobile'] = $mobile;
        $data['add_time'] = time();
//        $data['del_time'] = 0;
        $user_tuanti_company = M("user_tuanti_company");
        //查询是否添加了公司
        $cdst = $user_tuanti_company->where(['uid' => $uid, 'order_id' => $order_id])->count();
        if ($cdst) {
            $user_tuanti_company->where(['uid' => $uid, 'order_id' => $order_id])->save($data);
            $dcsayt = $user_tuanti_company->where(['uid' => $uid, 'order_id' => $order_id])->find();
            $data_cc['code'] = 200;
            $data_cc['msg'] = '查询成功';
            $data_cc['data'] = $dcsayt;
            exit(json_encode($data_cc));
        } else {
            $result = $user_tuanti_company->add($data);
            if ($result) {
                $minfo2 = $user_tuanti_company->where(['uid' => $uid, 'order_id' => $order_id])->find();
                $data_cc['code'] = 200;
                $data_cc['msg'] = '添加成功';
                $data_cc['data'] = $minfo2;
                exit(json_encode($data_cc));
            } else {
                $data_cc['code'] = 0;
                $data_cc['msg'] = '添加失败';
                exit(json_encode($data_cc));
            }
        }
    }

    //编辑
    public function edit_company()
    {
        $detail = I('');
        $company_id = $detail['company_id'];
        $order_id = $detail['order_id'] ?: 0;
        $company = $detail['company'];
        $names = $detail['names'];
        $mobile = $detail['mobile'];
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "订单Id不能为空";
            exit(json_encode($data_cc));
        }
        if (empty($company_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "公司不能为空";
            exit(json_encode($data_cc));
        }
        $model_user_order = M("user_order");
        $info = $model_user_order->where(['uid' => UID, 'id' => $order_id, 'isdel' => 0])->find();
        if (empty($info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "订单信息查询失败";
            exit(json_encode($data_cc));
        }
        $c_model = M("user_tuanti_company");
        $c_info = $c_model->where(['uid' => UID, 'id' => $company_id, 'order_id' => $order_id, 'isdel' => 0])->find();
        if (empty($c_info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "公司信息查询失败";
            exit(json_encode($data_cc));
        }
        if (empty($company)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请输入公司名称";
            exit(json_encode($data_cc));
        }
        if (empty($names)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请输入姓名";
            exit(json_encode($data_cc));
        }
        if (empty($mobile)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请输入手机号码";
            exit(json_encode($data_cc));
        }
        $s_data['company'] = $company;
        $s_data['names'] = $names;
        $s_data['mobile'] = $mobile;
        $res = $c_model->where(['uid' => UID, 'id' => $company_id, 'order_id' => $order_id, 'isdel' => 0])->save($s_data);
        if ($res) {
            $cc_info = $c_model->where(['uid' => UID, 'id' => $company_id, 'order_id' => $order_id, 'isdel' => 0])->find();
            $data_cc['code'] = 200;
            $data_cc['msg'] = "编辑成功";
            $data_cc['data'] = $cc_info;
            exit(json_encode($data_cc));
        } else {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "编辑失败";
            exit(json_encode($data_cc));
        }
    }

    //添加部门
    public function add_department()
    {
        $detail = I('post.');
        $uid = UID;
        $order_id = $detail['order_id'] ?: 0;
        $pid = $detail['pid'] ?: 0;
        $title = $detail['title'] ?: '';
        $number = $detail['number'] ?: 0;
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "order_id参数错误";
            exit(json_encode($data_cc));
        }
        $where['uid'] = $uid;
        $where['id'] = $order_id;
        $model_user_order = M("user_order");
        $info = $model_user_order->where($where)->find();
        $c_where['uid'] = $uid;
        $c_where['order_id'] = $order_id;
        $c_where['id'] = $pid;
        $c_where['isdel'] = 0;
        $user_tuanti_company = M("user_tuanti_company");
        $c_info = $user_tuanti_company->where($c_where)->find();
        if (empty($info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "信息查询失败";
            exit(json_encode($data_cc));
        }
        if (empty($c_info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "公司信息不存在";
            exit(json_encode($data_cc));
        }
        if (empty($title)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请输入部门名称";
            exit(json_encode($data_cc));
        }
        if (empty($number)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请输入部门人数";
            exit(json_encode($data_cc));
        }
        if (empty($pid)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "参数错误";
            exit(json_encode($data_cc));
        }
        $data['uid'] = $uid;
        $data['order_id'] = $order_id;
        $data['pid'] = $pid;
        $data['title'] = $title;
        $data['number'] = $number;
        $data['add_time'] = time();
        $department_model = M("user_tuanti_company_department");
        $count = $department_model->where(['uid' => $uid, 'order_id' => $order_id, 'pid' => $pid, 'title' => $title, 'isdel' => 0])->count();
        if ($count > 0) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "该公司已经存在该部门了";
            exit(json_encode($data_cc));
        }

        $result = $department_model->add($data);
        if ($result) {
            $data_cc['code'] = 200;
            $data_cc['msg'] = '添加成功';
            exit(json_encode($data_cc));
        } else {
            $data_cc['code'] = 200;
            $data_cc['msg'] = '添加失败';
            exit(json_encode($data_cc));
        }
    }

    //公司检测
    public function order_company_check()
    {
        $order_id = I('order_id');
        $o_model = M('user_order');
        $model = M('user_tuanti_company');
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '订单ID不能为空';
            exit(json_encode($data_cc));
        }
        $o_info = $o_model->where(['uid' => UID, 'id' => $order_id, 'isdel' => 0])->find();
        if (empty($o_info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '订单信息不存在';
            exit(json_encode($data_cc));
        }
        $info = $model->where(['uid' => UID, 'order_id' => $order_id, 'isdel' => 0])->find();
        if ($info) {
            $data_cc['code'] = 200;
            $data_cc['msg'] = '存在公司信息';
            $data_cc['data']['status'] = 1;
            $data_cc['data']['info'] = $info;
            exit(json_encode($data_cc));
        } else {
            $data_cc['code'] = 200;
            $data_cc['msg'] = '不存在公司信息';
            $data_cc['data']['status'] = 2;
            $data_cc['data']['info'] = [];
            exit(json_encode($data_cc));
        }
    }

    //订单部门列表
    public function order_department_list()
    {
        $order_id = I('order_id');
        $company_id = I('company_id');
        $page = $detail['page'] ? $detail['page'] : 1;
        $limit = $detail['limit'] ? $detail['limit'] : 10;
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '订单ID不能为空';
            exit(json_encode($data_cc));
        }
        if (empty($company_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '企业ID不能为空';
            exit(json_encode($data_cc));
        }
        $o_model = M('user_order');
        $c_model = M('user_tuanti_company');
        $o_info = $o_model->where(['uid' => UID, 'id' => $order_id, 'isdel' => 0])->find();
        if (empty($o_info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '订单信息不存在';
            exit(json_encode($data_cc));
        }
        $c_info = $c_model->where(['uid' => UID, 'id' => $company_id, 'order_id' => $order_id, 'isdel' => 0])->find();
        if (empty($o_info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '企业信息不存在';
            exit(json_encode($data_cc));
        }

        $keyword = I('keyword');
        if ($kewords) {
            $where['title'] = array('like', '%' . $keyword . '%');
        }
        $model = M("user_tuanti_company_department");
        $where['uid'] = UID;
        $where['order_id'] = $order_id;
        $where['pid'] = $company_id;
        $where['isdel'] = 0;
        $count = $model->where($where)->count();
        $list = $model->where($where)->order('id desc')->page($page, $limit)->select();
        $data_cc['code'] = 200;
        $data_cc['msg'] = '获取成功';
        $data_cc['data']['count'] = $count;
        $data_cc['data']['list'] = $list;
        exit(json_encode($data_cc));
    }

    //订单部门编辑
    public function order_department_edit()
    {
        $detail = I('');
        $order_id = $detail['order_id'];
        $company_id = $detail['company_id'];
        $department_id = $detail['department_id'];
        $title = $detail['title'];
        $number = $detail['number'];
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '订单ID不能为空';
            exit(json_encode($data_cc));
        }
        if (empty($company_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '企业ID不能为空';
            exit(json_encode($data_cc));
        }
        if (empty($number)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '部门人数不能为空';
            exit(json_encode($data_cc));
        }
        $o_model = M('user_order');
        $c_model = M('user_tuanti_company');
        $o_info = $o_model->where(['uid' => UID, 'id' => $order_id, 'isdel' => 0])->find();
        if (empty($o_info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '订单信息不存在';
            exit(json_encode($data_cc));
        }
        $c_info = $c_model->where(['uid' => UID, 'id' => $company_id, 'order_id' => $order_id, 'isdel' => 0])->find();
        if (empty($o_info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '企业信息不存在';
            exit(json_encode($data_cc));
        }
        $d_model = M("user_tuanti_company_department");
        $d_info = $d_model->where(['uid' => UID, 'id' => $department_id, 'pid' => $company_id, 'order_id' => $order_id, 'isdel' => 0])->find();
        if (empty($d_info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '部门信息不存在';
            exit(json_encode($data_cc));
        }
        $model = M('user_tuantidingzhi');
        $count = $model->where(['uid' => UID, 'part_id' => $department_id, 'comp_id' => $company_id, 'order_id' => $order_id, 'isdel' => 0])->count();
        if ($number < $count) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '当前录入数据的数量大于要修改的数量';
            exit(json_encode($data_cc));
        }

        $d_count = $d_model->where(['uid' => UID, 'id' => array('neq', $department_id), 'order_id' => $order_id, 'pid' => $pid, 'title' => $title, 'isdel' => 0])->count();
        if ($d_count > 0) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "该公司已经存在该部门了";
            exit(json_encode($data_cc));
        }
        $s_data['title'] = $title;
        $s_data['number'] = $number;
        $res = $d_model->where(['uid' => UID, 'id' => $department_id, 'pid' => $company_id, 'order_id' => $order_id, 'isdel' => 0])->save($s_data);
        if ($res) {
            $data_cc['code'] = 200;
            $data_cc['msg'] = '编辑成功';
            exit(json_encode($data_cc));
        } else {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '编辑失败';
            exit(json_encode($data_cc));
        }
    }

    //订单部门删除
    public function order_department_del()
    {
        $detail = I('');
        $order_id = $detail['order_id'];
        $company_id = $detail['company_id'];
        $department_id = $detail['department_id'];
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '订单ID不能为空';
            exit(json_encode($data_cc));
        }
        if (empty($company_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '企业ID不能为空';
            exit(json_encode($data_cc));
        }
        $o_model = M('user_order');
        $c_model = M('user_tuanti_company');
        $o_info = $o_model->where(['uid' => UID, 'id' => $order_id, 'isdel' => 0])->find();
        if (empty($o_info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '订单信息不存在';
            exit(json_encode($data_cc));
        }
        $c_info = $c_model->where(['uid' => UID, 'id' => $company_id, 'order_id' => $order_id, 'isdel' => 0])->find();
        if (empty($o_info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '企业信息不存在';
            exit(json_encode($data_cc));
        }
        $d_model = M("user_tuanti_company_department");
        $d_info = $d_model->where(['uid' => UID, 'id' => $department_id, 'pid' => $company_id, 'order_id' => $order_id, 'isdel' => 0])->find();
        if (empty($d_info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '部门信息不存在';
            exit(json_encode($data_cc));
        }
        $model = M('user_tuantidingzhi');
        $count = $model->where(['uid' => UID, 'part_id' => $department_id, 'comp_id' => $company_id, 'order_id' => $order_id, 'isdel' => 0])->count();
        if ($count > 0) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '当前部门存在录入数据,无法删除';
            exit(json_encode($data_cc));
        }
        $s_data['isdel'] = 1;
        $s_data['del_time'] = time();
        $res = $d_model->where(['uid' => UID, 'id' => $department_id, 'pid' => $company_id, 'order_id' => $order_id, 'isdel' => 0])->save($s_data);
        if ($res) {
            $data_cc['code'] = 200;
            $data_cc['msg'] = '删除成功';
            exit(json_encode($data_cc));
        } else {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '删除失败';
            exit(json_encode($data_cc));
        }
    }

    //插入团体定制数据
    public function addctup()
    {
        $data = $detail = I('post.');
        $uid = UID;
        $order_id = $detail['order_id'] ?: 0;
        $comp_id = $detail['comp_id'] ?: 0;
        $part_id = $detail['part_id'] ?: 0;
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "order_id参数错误";
            exit(json_encode($data_cc));
        }
        if (empty($comp_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "comp_id参数错误";
            exit(json_encode($data_cc));
        }
        if (empty($part_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "part_id参数错误";
            exit(json_encode($data_cc));
        }

        $where['uid'] = $uid;
        $where['id'] = $order_id;
        $c_where['uid'] = $uid;
        $c_where['order_id'] = $order_id;
        $c_where['id'] = $comp_id;
        $c_where['isdel'] = 0;

        $t_where['uid'] = $uid;
        $t_where['order_id'] = $order_id;
        $t_where['id'] = $part_id;
        $t_where['isdel'] = 0;

        $model_user_order = M("user_order");
        $user_tuanti_company = M("user_tuanti_company");
        $user_tuanti_company_department = M("user_tuanti_company_department");
        $info = $model_user_order->where($where)->find();
        $info_comp = $user_tuanti_company->where($c_where)->find();
        $info_bumenb = $user_tuanti_company_department->where($t_where)->find();

        if (empty($info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "信息查询失败";
            exit(json_encode($data_cc));
        }
        if (empty($info_comp)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "公司信息查询失败";
            exit(json_encode($data_cc));
        }
        if (empty($info_bumenb)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "部门信息查询失败";
            exit(json_encode($data_cc));
        }

        $names = $data['names'];
        $fcount = count($names);
        //查询该部门最多可以添加多少条数据
        $user_tuanti_company_department = M("user_tuanti_company_department");
        $whec['isdel'] = 0;
        $whec['order_id'] = $order_id;
        $whec['uid'] = $uid;
        $whec['pid'] = $comp_id;
        $whec['id'] = $part_id;
        $number = $user_tuanti_company_department->where($whec)->getField('number');
        $whec2['isdel'] = 0;
        $whec2['order_id'] = $order_id;
        $whec2['uid'] = $uid;
        $whec2['comp_id'] = $comp_id;
        $whec2['part_id'] = $part_id;
        //统计数据库条数
        $pattr_tuantidingzhi = M("user_tuantidingzhi");
        //  $cdat_count=$pattr_tuantidingzhi->where($whec2)->count();
        //  $total=$cdat_count+$fcount;
        $total = $fcount;
        if ($total > $number) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "该部门最多只能添加" . $number . '人信息。';
            exit(json_encode($data_cc));
        }

        $mctv = [];
        foreach ($names as $k => $val) {
            $mctv['order_id'] = $order_id;
            $mctv['uid'] = $uid;
            $mctv['comp_id'] = $comp_id;
            $mctv['part_id'] = $part_id;
            $mctv['id'] = $data['id'][$k] ? $data['id'][$k] : '';
            $mctv['names'] = $val;
            $mctv['age'] = $data['age'][$k];
            $mctv['sex'] = $data['sex'][$k];
            $mctv['height'] = $data['height'][$k];
            $mctv['xmcm'] = $data['xmcm'][$k];
            $mctv['weight'] = $data['weight'][$k];
            $mctv['xfcm_qcy'] = $data['xfcm_qcy'][$k];
            $mctv['xfcm_hzy'] = $data['xfcm_hzy'][$k];
            //$mctv['xfcm_jxw'] = $data['xfcm_jxw'][$k];
            $mctv['xfcm_cyxw'] = $data['xfcm_cyxw'][$k];
            $mctv['xfcm_xc'] = $data['xfcm_xc'][$k];
            $mctv['xfcm_jk'] = $data['xfcm_jk'][$k];
            $mctv['xfcm_yw'] = $data['xfcm_yw'][$k];
            $mctv['xkcm'] = $data['xkcm'][$k];
            $mctv['xfcm_zy'] = $data['xfcm_zy'][$k];
            //$mctv['xkcm_jyw'] = $data['xkcm_jyw'][$k];
            $mctv['xkcm_cyyw'] = $data['xkcm_cyyw'][$k];
            //$mctv['xkcm_jtw'] = $data['xkcm_jtw'][$k];
            $mctv['xkcm_cytw'] = $data['xkcm_cytw'][$k];
            $mctv['xkcm_hd'] = $data['xkcm_hd'][$k];
            $mctv['xkcm_qkc'] = $data['xkcm_qkc'][$k];
            $mctv['number'] = $data['number'][$k];
            $mctv['remark'] = $data['remark'][$k];
            //新增
            $mctv['unit'] = $data['unit'][$k];
            $mctv['xiuwei'] = $data['xiuwei'][$k];
            $mctv['xiabai'] = $data['xiabai'][$k];
            $mctv['linwei'] = $data['linwei'][$k];
            $mctv['tuiwei'] = $data['tuiwei'][$k];
            $mctv['jiaokou'] = $data['jiaokou'][$k];
            $mctv['addtime'] = date("Y-m-d H:i:s");
            $dfsg[] = $mctv;
        }

        if ($dfsg) {
            foreach ($dfsg as $k => $val) {
                $mct = $pattr_tuantidingzhi->where(['order_id' => $val['order_id'], 'uid' => $uid, 'id' => $val['id']])->count();
                if ($mct) {
                    $ids = $val['id'];
                    unset($val['id']);
                    $pattr_tuantidingzhi->where(['order_id' => $val['order_id'], 'uid' => $uid, 'id' => $ids])->save($val);
                } else {
                    unset($val['id']);
                    $pattr_tuantidingzhi->add($val);
                }
            }
            $data2 = $pattr_tuantidingzhi->where(['order_id' => $order_id, 'uid' => $uid])->order('id asc ')->select();
            $data_cc = [];
            $data_cc['code'] = 200;
            $data_cc['msg'] = '批量操作成功';
            exit(json_encode($data_cc));
        } else {
            $data_cc = [];
            $data_cc['code'] = 0;
            $data_cc['msg'] = '查询失败';
            exit(json_encode($data_cc));
        }

    }

    //查询团体信息
    public function get_tuantiinfo()
    {
        $data = $detail = I('post.');
        $uid = UID;
        $order_id = $detail['order_id'] ?: 0;
        $comp_id = $detail['comp_id'] ?: 0;
        $part_id = $detail['part_id'] ?: 0;
        // $page=$detail['page']?$detail['page']:1;
        // $limit=$detail['limit']?$detail['limit']:15; 
        // $kewords=$detail['kewords']?:'';
        $sort_type = $detail['sort_type']; //xmcm 上装尺码；xkcm 下装尺码
        $sort = $detail['sort'];// asc 升序；desc;降序
        if ($sort_type != '' && $sort != '') {
            $sort_str = $sort_type . ' ' . $sort;
        } else {
            $sort_str = 'id desc';
        }


        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "order_id参数错误";
            exit(json_encode($data_cc));
        }
        if (empty($comp_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "comp_id参数错误";
            exit(json_encode($data_cc));
        }
        if (empty($part_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "part_id参数错误";
            exit(json_encode($data_cc));
        }
        $where['uid'] = $uid;
        $where['id'] = $order_id;
        $model_user_order = M("user_order");
        $info = $model_user_order->where($where)->find();
        if (empty($info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "信息查询失败";
            exit(json_encode($data_cc));
        }
        $keyword = I('keyword');
        $user_tuantidingzhi = M("user_tuantidingzhi");
        $user_tuanti_company_department = M("user_tuanti_company_department");
        $whte['order_id'] = $order_id;
        $whte['uid'] = $uid;
        $whte['part_id'] = $part_id;
        $whte['comp_id'] = $comp_id;
        $whte['isdel'] = 0;
        if ($keyword) {
            $whte['names|remark'] = ['like', '%' . $keyword . '%'];
        }
        //xmcm 西服尺码  xkcm 西裤尺码
        // $count  = $user_tuantidingzhi->where($whte)->count();
        $list = $user_tuantidingzhi->where($whte)->order($sort_str)->select();
        $whec['isdel'] = 0;
        $whec['order_id'] = $order_id;
        $whec['uid'] = $uid;
        $whec['pid'] = $comp_id;
        $whec['id'] = $part_id;
        $info_cc = $user_tuanti_company_department->where($whec)->find();
        $data_cc['code'] = 200;
        $data_cc['msg'] = '操作成功';
        $data_cc['info'] = $info_cc;
        // $data_cc['count']=$count;
        $data_cc['list'] = $list;
        exit(json_encode($data_cc));
    }

    //查询自由信息列表
    public function list_zymc()
    {
        $detail = I('post.');
        $uid = UID;
        $order_id = $detail['order_id'];
        $model_user_order = M("user_order");
        $user_ziyou_img = M('user_ziyou_img');
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "order_id参数错误";
            exit(json_encode($data_cc));
        }
        $where['uid'] = $uid;
        $where['id'] = $order_id;
        $info = $model_user_order->where($where)->find();
        if (empty($info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "信息查询失败";
            exit(json_encode($data_cc));
        }
        $list = [];
        $whetc['order_id'] = $order_id;
        $whetc['uid'] = $uid;
        $whetc['isdel'] = 0;
        $list = $user_ziyou_img->where($whetc)->field('id,img,desct')->order("id desc")->select();
        $data_cc['code'] = 200;
        $data_cc['msg'] = "查询成功";
        $data_cc['list'] = $list;
        exit(json_encode($data_cc));
    }

    public function del_zymc()
    {
        $detail = I('post.');
        $id = $detail['id'];
        $uid = UID;
        $order_id = $detail['order_id'];
        $user_ziyou_img = M('user_ziyou_img');
        $model_user_order = M("user_order");
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "order_id参数错误";
            exit(json_encode($data_cc));
        }
        $where['uid'] = $uid;
        $where['id'] = $order_id;
        $info = $model_user_order->where($where)->find();
        if (empty($info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "信息查询失败";
            exit(json_encode($data_cc));
        }
        $stf_info1 = $user_ziyou_img->where(['id' => $id, 'uid' => $uid, 'order_id' => $order_id])->find();
        if (empty($stf_info1)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "信息查询失败";
            exit(json_encode($data_cc));
        }
        $resault = $user_ziyou_img->where(['id' => $id, 'uid' => $uid, 'order_id' => $order_id])->save(['isdel' => 1, 'del_time' => time()]);
        if ($resault) {
            $data_cc['code'] = 200;
            $data_cc['msg'] = "删除成功";
        } else {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "删除失败";
        }
        exit(json_encode($data_cc));
    }

    //自由信息里面添加图片
    public function add_zymc()
    {
        $detail = I('post.');
        $uid = UID;
        $order_id = $detail['order_id'];
        $id = $detail['id'];
        $img = $detail['img'];
        $data['order_id'] = $order_id;
        $data['img'] = $img;
        $data['uid'] = $uid;
        $data['desct'] = $detail['desct'];
        $data['add_time'] = time();
        $user_ziyou_img = M('user_ziyou_img');
        $model_user_order = M("user_order");
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "order_id参数错误";
            exit(json_encode($data_cc));
        }
        $where['uid'] = $uid;
        $where['id'] = $order_id;
        $info = $model_user_order->where($where)->find();
        if (empty($info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "订单查询失败";
            exit(json_encode($data_cc));
        }
        if (empty($img)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "请上传图片";
            exit(json_encode($data_cc));
        }
        $minfo = $user_ziyou_img->where(['id' => $id, 'uid' => $uid, 'order_id' => $order_id])->count();
        if ($minfo) {
            $resault = $user_ziyou_img->where(['id' => $id, 'uid' => $uid, 'order_id' => $order_id])->save($data);
            $msg = '编辑';
        } else {
            $resault = $user_ziyou_img->add($data);
            $msg = '添加';
        }
        $list = $user_ziyou_img->where(['uid' => $uid, 'order_id' => $order_id])->select();
        if ($resault) {
            $data_cc['code'] = 200;
            $data_cc['data'] = $list;
            $data_cc['msg'] = $msg . "成功";
        } else {
            $data_cc['code'] = 0;
            $data_cc['msg'] = $msg . "失败";
        }
        exit(json_encode($data_cc));
    }
    // //新增自由信息
    // public function add_attr(){
    //     $detail = I('post.');
    //     $uid=UID;
    //     $order_id=$detail['order_id'];
    //     $model_user_order=M("user_order"); 
    //     $user_order_attr=M("user_order_attr"); 
    //     if(empty($order_id)){
    //         $data_cc['code'] = 0;
    //         $data_cc['msg'] = "order_id参数错误";
    //         exit(json_encode($data_cc));
    //     }
    //     $where['uid']=$uid; 
    //     $where['id']=$order_id;
    //     $info = $model_user_order->where($where)->find();
    //     if(empty($info)){
    //         $data_cc['code'] = 0;
    //         $data_cc['msg'] = "订单查询失败";
    //         exit(json_encode($data_cc));
    //     }
    //     $names=$detail['names'];
    //     $cds_count=count($names);
    //     if($cds_count==0){
    //         $data_cc['code'] = 0;
    //         $data_cc['msg'] = "请输入字段名";
    //         exit(json_encode($data_cc));
    //     }
    //     $valc=$detail['val'];
    //     $id=$detail['id'];
    //     $dfad=[];
    //     foreach($names as $k=>$val){
    //          $dfad['names']=$val;
    //          $dfad['uid']=$uid;
    //          $dfad['order_id']=$order_id;
    //          if(empty($valc[$k])){
    //             $data_cc['code'] = 0;
    //             $data_cc['msg'] = "请输入字段对应的值";
    //             exit(json_encode($data_cc));
    //          }
    //          $dfad['val']=$valc[$k];
    //          $dfad['id']=$id[$k];
    //          $datx[]=$dfad;
    //     }
    //     if($datx){
    //          foreach($datx as $kt=>$valcc){
    //             $count=$user_order_attr->where(['id'=>$valcc['id'],'uid'=>$uid,'order_id'=>$order_id])->count();
    //             if($count){
    //                  $sid=$valcc['id'];
    //                  unset($valcc['id']);
    //                  $user_order_attr->where(['id'=>$sid,'uid'=>$uid,'order_id'=>$order_id])->save($valcc);
    //             }else{
    //                  unset($valcc['id']);
    //                  $user_order_attr->add($valcc);
    //             }  
    //          }
    //     }
    //     $data_cc['code'] = 200;
    //     $data_cc['msg'] = "编辑成功";
    //     $data_cc = $this->ziyouint($order_id);
    //     exit(json_encode($data_cc));
    // }

    function add_attr()
    {
        if (!I('order_id')) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "订单必须填写";
            exit(json_encode($data_cc));
        }
        $order_id = I('order_id');
        $attr_model = M("user_order_attr");
        $order_model = M("user_order");
        $names = I('names');
        $vals = I('val');
        $sort = I('sort');
        $order_info = $order_model->where(['id' => $order_id, 'uid' => UID, 'isdel' => 0])->find();
        if (empty($order_info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "订单信息不存在";
            exit(json_encode($data_cc));
        }
        $del_wdata['order_id'] = $order_id;
        $del_wdata['uid'] = UID;
        $del_wdata['isdel'] = 0;
        $res = $attr_model->where($del_wdata)->save(['isdel' => 1, 'del_time' => time()]);
        foreach ($names as $key => $name) {
            if ($name === '' || $vals[$key] === '') {
                continue;
            }
            $data = [];
            $data['uid'] = UID;
            $data['order_id'] = $order_id;
            $data['names'] = $name;
            $data['isdel'] = 0;
            $count = $attr_model->where($data)->count();
            if ($count == 0) {
                $data['val'] = $vals[$key];
                $data['sort'] = $sort[$key] ?: 200;
                $data['add_time'] = NOW_TIME;
                $attr_model->add($data);
            } else {
                $wdata = $data;
                $data['val'] = $vals[$key];
                $data['sort'] = $sort[$key] ?: 200;
                $data['add_time'] = NOW_TIME;
                $r = $attr_model->where($wdata)->save($data);
            }
        }
        $data_cc['code'] = 200;
        $data_cc['msg'] = "操作成功";
        $data_cc['data'] = $this->getZdy($order_id);
        exit(json_encode($data_cc));
    }

    //自由信息
    function getZdy($order_id)
    {
        $model = M('user_order_attr');
        $wdata['order_id'] = $order_id;
        $wdata['uid'] = UID;
        $wdata['isdel'] = 0;
        $list = $model->where($wdata)->order('sort asc,id asc')->select();
        foreach ($list as $val) {
            $val_list[] = explode(',', $val['val']);
            unset($val['val']);
            $data['name_list'][] = $val;
        }
        $v_list = [];
        foreach ($val_list as $vals) {
            foreach ($vals as $key => $val) {
                $v_list[$key][] = $val;
            }
        }
        $data['val_list'] = $v_list;
        return $data ?: [];
    }

    //查询自由xinxi
    public function get_ziyoudetail()
    {
        $detail = I('post.');
        $uid = UID;
        $order_id = $detail['order_id'];
        $model_user_order = M("user_order");
        $stf_info = $model_user_order->where(['id' => $order_id])->find();
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "order_id参数错误";
            exit(json_encode($data_cc));
        }
        $where['uid'] = $uid;
        $where['id'] = $order_id;
        $info = $model_user_order->where($where)->find();
        if (empty($info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "信息查询失败";
            exit(json_encode($data_cc));
        }
        $data_cc['code'] = 200;
        $data_cc['msg'] = "查询成功";
        $data_cc['data'] = $this->getZdy($order_id);
        exit(json_encode($data_cc));
    }

    //草稿箱详情
    public function get_order_detail()
    {
        $detail = I('post.');
        $uid = UID;
        $order_id = $detail['order_id'];
        $model_user_order = M("user_order");
        $user_ziyou_img = M('user_ziyou_img');
        $stf_info = $model_user_order->where(['id' => $order_id])->find();
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "order_id参数错误";
            exit(json_encode($data_cc));
        }
        $where['uid'] = $uid;
        $where['id'] = $order_id;
        $where['isdel'] = 0;
        $info = $model_user_order->where($where)->find();
        if (empty($info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "信息查询失败";
            exit(json_encode($data_cc));
        }

        $data_cc['code'] = 200;
        $data_cc['msg'] = "查询成功";
        $data_cc['order_info'] = $info;
        $data_cc['order_kuanshi'] = $this->get_kuanshicc($order_id);
        $data_cc['order_gongyi'] = $this->get_kuanshicc($order_id, 1);
        $data_cc['order_sirendingz'] = $this->customer_info($order_id);
        $data_cc['order_tuanti'] = $this->get_tuantixc($order_id);
        $data_cc['ziyou_info'] = $this->ziyouint($order_id);
        exit(json_encode($data_cc));
    }

    function customer_info($order_id)
    {
        $uid = UID;
        $user_private_customer = M("user_private_customer");
        $user_private_order = M("user_private_order");
        $user_private_sybz = M("user_private_sybz");
        $user_private_tstx = M("user_private_tstx");
        $user_tstx_pic = M("user_private_pic");
        $info = $user_private_customer->where(['order_id' => $order_id, 'uid' => $uid, 'isdel' => 0])->field('id,customer_name,sex,age,high,weight,cat_id,upper_id,below_id')->find();
        $tuanti_list = $user_private_order->where(['order_id' => $order_id, 'uid' => $uid, 'isdel' => 0])->field('id,names,bodysize,pro_size,shiyi_fitting')->order('id asc')->select();
        $shiyibeizhu = $user_private_sybz->where(['order_id' => $order_id, 'uid' => $uid, 'isdel' => 0])->field('id,taomayi,palin,jianxie,houyaojie')->find();
        //$tesutix=$user_private_tstx->where(['order_id'=>$order_id,'uid'=>$uid,'isdel'=>0])->field('id,cid,pid,remark')->order('id asc')->select();
        $tesutix = $user_private_tstx->alias('a')->join('`fa_renshi_img` as b on a.cid=b.id')->where(['a.order_id' => $order_id, 'a.uid' => $uid, 'a.isdel' => 0])->field('a.id,a.cid as tx_id,a.pid,a.remark,b.title,b.img as pic,b.pid as cat_id')->order('id asc')->select();
        if ($tesutix) {
            /*
            foreach($tesutix as $k=>$val){
               $m_int=$this->get_childsc($val['cid']);
               $tesutix[$k]['tx_id']=$m_int['id'];
               $tesutix[$k]['title']=$m_int['title'];
               $tesutix[$k]['pic']=$m_int['pic'];
            }
            */
        }
        $picc = $user_tstx_pic->where(['order_id' => $order_id, 'uid' => $uid, 'isdel' => 0])->getField('picc');
        $mt['customer_info'] = $info;
        $mt['tuanti_list'] = $tuanti_list ?: [];
        $mt['shiyibeizhu'] = $shiyibeizhu ?: [];
        $mt['tesutix'] = $tesutix ?: [];
        $mt['kh_picc'] = $picc ?: "";
        return $mt;
    }

    function cleart($order_id)
    {
        $uid = UID;
        $user_private_customer = M("user_private_customer");
        $user_private_order = M("user_private_order");
        $user_private_sybz = M("user_private_sybz");
        $user_private_tstx = M("user_private_tstx");
        $user_tstx_pic = M("user_private_pic");
        $user_private_customer->where(['order_id' => $order_id, 'uid' => $uid, 'isdel' => 0])->save(['isdel' => 1]);
        $user_private_order->where(['order_id' => $order_id, 'uid' => $uid, 'isdel' => 0])->save(['isdel' => 1]);
        $user_private_sybz->where(['order_id' => $order_id, 'uid' => $uid, 'isdel' => 0])->save(['isdel' => 1]);
        $user_private_tstx->where(['order_id' => $order_id, 'uid' => $uid, 'isdel' => 0])->save(['isdel' => 1]);
        $user_tstx_pic->where(['order_id' => $order_id, 'uid' => $uid, 'isdel' => 0])->save(['isdel' => 1]);
    }

    public function get_childsc($id)
    {
        $user_tstx_pic = M("user_tstx_pic");
        $cc = $user_tstx_pic->where(['id' => $id, 'isdel' => 0])->field('id,title,pic')->find();
        return $cc;
    }

    public function order_submit()
    {
        $detail = I('post.');
        $uid = UID;
        $order_id = $detail['order_id'];
        $order = M('user_order');
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "order_id参数错误";
            exit(json_encode($data_cc));
        }
        $model_user_order = M("user_order");
        $where['uid'] = $uid;
        $where['id'] = $order_id;
        $info = $model_user_order->where($where)->find();
        if (empty($info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "信息查询失败";
            exit(json_encode($data_cc));
        }
        $model_user_order->where($where)->save(['qure_time' => time(), 'status' => 1]);
        $data_cc['code'] = 200;
        $data_cc['msg'] = "操作成功";
        exit(json_encode($data_cc));
    }

    //查询自由信息
    function ziyouint($order_id)
    {
        $detail = I('post.');
        $uid = UID;
        $order_id = $detail['order_id'];
        $model_user_order = M("user_order");
        // $user_order_attr=M("user_order_attr"); 
        $user_ziyou_img = M("user_ziyou_img");
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "order_id参数错误";
            exit(json_encode($data_cc));
        }
        $where['uid'] = $uid;
        $where['id'] = $order_id;
        $info = $model_user_order->where($where)->find();
        if (empty($info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "订单查询失败";
            exit(json_encode($data_cc));
        }
        $wher_c['uid'] = $uid;
        $wher_c['order_id'] = $order_id;
        $wher_c['isdel'] = 0;
        // $list=$user_order_attr->where($wher_c)->order('id asc')->select();
        $picc_list = $user_ziyou_img->where($wher_c)->order('id asc')->select();
        $cc['list'] = $this->getZdy($order_id);
        $cc['picc_list'] = $picc_list;
        return $cc;

    }

    //添加试衣备注
    function add_sybz($info, $mt_data)
    {
        $data['taomayi'] = $info['taomayi'];
        $data['palin'] = $info['palin'];
        $data['jianxie'] = $info['jianxie'];
        $data['houyaojie'] = $info['houyaojie'];
        $data['order_id'] = $mt_data['order_id'];
        $data['uid'] = $uid = $mt_data['uid'];
        $user_mysql_cate = M("user_private_sybz");
        $count = $user_mysql_cate->where(['uid' => $uid, 'order_id' => $mt_data['order_id'], 'isdel' => 0])->count();
        if ($count) {
            $user_mysql_cate->where(['uid' => $uid, 'order_id' => $mt_data['order_id']])->save($data);
        } else {
            $data['add_time'] = time();
            $user_mysql_cate->add($data);
        }
    }

    //添加团体定制信息
    function add_tuanti($info, $mt_data)
    {
        $user_private_order = M("user_private_order");
        $post = I('post.');
        if ($post) {
            $names = $post['names'];
            $bodysize = $post['bodysize'];
            $pro_size = $post['pro_size'];
            $shiyi_fitting = $post['shiyi_fitting'];
            $shiyi_fitting2 = $post['shiyi_fitting2'];
            $shiyi_fitting3 = $post['shiyi_fitting3'];
            foreach ($names as $k => $val) {
                $data = [];
                $data['names'] = $names[$k];
                $data['bodysize'] = $bodysize[$k];
                $data['pro_size'] = $pro_size[$k];
                if ($shiyi_fitting[$k]) {
                    $data['shiyi_fitting'] = $shiyi_fitting[$k];
                }
                if ($shiyi_fitting2[$k]) {
                    $data['shiyi_fitting2'] = $shiyi_fitting2[$k];
                }
                if ($shiyi_fitting3[$k]) {
                    $data['shiyi_fitting3'] = $shiyi_fitting3[$k];
                }
                $data['order_id'] = $mt_data['order_id'];
                $data['uid'] = $uid = $mt_data['uid'];
                $data['add_time'] = time();
                $fsger[] = $data;
            }
        }
        if ($fsger) {
            foreach ($fsger as $k1 => $vals) {
                $sdata = [];
                $count = $user_private_order->where(['uid' => $uid, 'order_id' => $vals['order_id'], 'names' => $vals['names'], 'isdel' => 0])->count();
                if ($count) {
                    $wdata['uid'] = $uid;
                    $wdata['order_id'] = $vals['order_id'];
                    $wdata['names'] = $vals['names'];
                    $sdata['bodysize'] = $vals['bodysize'];
                    $sdata['pro_size'] = $vals['pro_size'];
                    if ($vals['shiyi_fitting']) $sdata['shiyi_fitting'] = $vals['shiyi_fitting'];
                    if ($vals['shiyi_fitting2']) $sdata['shiyi_fitting2'] = $vals['shiyi_fitting2'];
                    if ($vals['shiyi_fitting3']) $sdata['shiyi_fitting3'] = $vals['shiyi_fitting3'];
                    $user_private_order->where($wdata)->save($sdata);
                } else {
                    $user_private_order->add($vals);
                }
            }
        }

    }

    function add_tstx($info, $mt_data)
    {
        $user_private_tstx = M("user_private_tstx");
        $post = I('post.');
        if ($post) {
            $cid = $post['cid'];
            $remark = $post['remark'];
            foreach ($cid as $k => $val) {
                $data['cid'] = $val;
                $data['pid'] = 4;
                $data['remark'] = $remark[$k];
                $data['order_id'] = $mt_data['order_id'];
                $data['uid'] = $uid = $mt_data['uid'];
                $data['add_time'] = time();
                $fsger[] = $data;
            }
        }
        if ($fsger) {
            foreach ($fsger as $k1 => $vals) {
                $count = $user_private_tstx->where(['uid' => $uid, 'order_id' => $vals['order_id'], 'pid' => $vals['pid'], 'isdel' => 0])->count();
                if ($count) {
                    $user_private_tstx->where(['uid' => $uid, 'order_id' => $vals['order_id'], 'pid' => $vals['pid']])->save(['cid' => $vals['cid'], 'remark' => $vals['remark']]);
                } else {
                    $user_private_tstx->add($vals);
                }
            }
        }
    }

    //添加体型照片
    function add_txphote($picc, $mt_data)
    {
        $user_private_pic = M("user_private_pic");
        $uid = UID;
        $user_private_tstx = M("user_private_tstx");
        if ($picc) {
            $data['picc'] = $picc;
            $data['order_id'] = $mt_data['order_id'];
            $data['uid'] = $uid = $mt_data['uid'];
            $data['add_time'] = time();
        }
        if ($data) {
            $count = $user_private_pic->where(['uid' => $uid, 'order_id' => $data['order_id'], 'isdel' => 0])->count();
            if ($count) {
                $user_private_pic->where(['uid' => $uid, 'order_id' => $data['order_id']])->save(['picc' => $data['picc']]);
            } else {
                $user_private_pic->add($data);
            }
        }
    }


    //查询大类和子分类
    function get_child($cate_id, $type)
    {
        $user_mysql_cate = M("user_mysql_cate");
        $uid = UID;
        $list = $user_mysql_cate->where(['pid' => $cate_id, 'uid' => $uid, 'stype' => $type, 'isdel' => 0])->select();
        $mcate = $cate_id . ",";
        if ($list) {
            foreach ($list as $k => $val) {
                $mcate .= $val['id'] . ",";
            }
        }
        $mcate = rtrim($mcate, ',');
        return $mcate;
    }

    //查询大类和子分类
    function get_childcc($cate_id, $type)
    {
        $imgcate = M("imgcate");
        $uid = UID;
        $list = $imgcate->where(['pid' => $cate_id, 'status' => $type, 'is_delete' => 0])->select();
        $mcate = $cate_id . ",";
        if ($list) {
            foreach ($list as $k => $val) {
                $mcate .= $val['id'] . ",";
            }
        }
        $mcate = rtrim($mcate, ',');
        return $mcate;
    }

    function get_kuanshicc($order_id, $type = 0)
    {
        $uid = UID;
        $user_cart = M("user_cart");
        $where['ct.isdel'] = 0;
        $where['ct.uid'] = $uid;
        $where['ct.order_id'] = $order_id;
        $where['ct.stype'] = $type;
        if ($type == 1) {
            $list = $user_cart->alias('ct')->join('left join fa_renshi_user_technology AS t ON t.id=ct.goods_id')->where($where)
                ->order('ct.id desc')
                ->field('ct.id,ct.goods_id,t.title as goods_name,t.pic_img as goods_img')
                ->select();
        } else {

            $list = $user_cart->alias('ct')->join('left join fa_renshi_user_goods AS g ON g.id=ct.goods_id')->where($where)
                ->order('ct.id desc')
                ->field('ct.id,ct.goods_id,g.goods_name,g.goods_sn,g.chenfen,g.goods_img')
                ->select();
        }
        return $list;

    }

    //查询团体定制信息
    function get_tuantixc($order_id)
    {
        $user_tuanti_company = M("user_tuanti_company");
        $uid = UID;
        $user_tuantidingzhi = M("user_tuantidingzhi");
        $user_tuanti_company_department = M("user_tuanti_company_department");
        $whcde['order_id'] = $order_id;
        $whcde['uid'] = $uid;
        $company = $user_tuanti_company->where($whcde)->find();
        $pid = $company['id'];
        if ($pid) {
            $list = $user_tuanti_company_department->where(['pid' => $pid, 'uid' => $uid, 'isdel' => 0])->field('id,title,number')->select();
            if ($list) {
                foreach ($list as $k => $val) {
                    $lsitc = $user_tuantidingzhi->where(['comp_id' => $pid, 'part_id' => $val['id'], 'isdel' => 0])->select();
                    $list[$k]['list'] = $lsitc;
                }
            }
            $fdag['company_info'] = $company;
            $fdag['list'] = $list;
            return $fdag;
        }
    }

    //删除订单里面所有信息
    function delt($order_id)
    {
        $where['uid'] = UID;
        $where['order_id'] = $order_id;
        $where['isdel'] = 0;
        $model_cc = 'user_order_attr,user_tuantidingzhi,user_cart,user_ziyou_img,user_private_tstx,user_private_sybz,user_private_pic,user_private_order,user_private_customer,user_tuanti_company_department,user_tuanti_company';
        $save['isdel'] = 1;
        $save['del_time'] = time();
        $list = explode(',', $model_cc);
        foreach ($list as $val) {
            M($val)->where($where)->save($save);
        }
        M('user_order')->where(['id' => $order_id, 'isdel' => 0, 'uid' => UID])->save($save);
    }

    //模板下载
    public function export()
    {
        $str = '团体定制模板';
        $data[] = '顾客姓名';
        $data[] = '年龄';
        $data[] = '性别';
        $data[] = '身高';
        $data[] = '体重';
        $data[] = '数量';
        $data[] = '备注';
        $data[] = '西服尺寸';
        $data[] = '前衣长';
        $data[] = '后中长';
        $data[] = '净胸围';
        $data[] = '成衣胸围';
        $data[] = '中腰';
        $data[] = '成衣腰围';
        $data[] = '肩宽';
        $data[] = '袖长';
        $data[] = '西裤尺寸';
        $data[] = '裤净腰围';
        $data[] = '成品腰围';
        $data[] = '净臀围';
        $data[] = '成衣臀围';
        $data[] = '横档';
        $data[] = '裙/裤长';
        $xlsCell = $data;
        $data = [];
        tuan_exportExcel($str, $xlsCell, $data);
    }

    //导入Excel
    public function import()
    {
        //$url = 'https://wages-zymaimai.oss-cn-beijing.aliyuncs.com/2023/04/15/643a6ad9f0698.xlsx';
        $excel_path = I('excel_path');
        $number = I('number');
        if (!$excel_path) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = 'excel地址必须！';
            exit(json_encode($data_cc));
        }
        $path = UID . '_attn.xlsx';//考勤excel
        file_put_contents($path, file_get_contents($excel_path));
        $exc_data = importExcel($path);
        $exc_count = count($exc_data);
        if ($exc_count > $number) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '超出部门人数,请修改部门人数';
            exit(json_encode($data_cc));
        }

        $data = [];
        $num = 0;
        foreach ($exc_data as $key => $val) {
            if ($key == 0 || $key == 1) {
                continue;
            }
            $data[$num]['names'] = $val[0];
            $data[$num]['age'] = $val[1];
            $data[$num]['sex'] = $val[2] == '男' ? 1 : 0;
            $data[$num]['height'] = $val[3];
            $data[$num]['weight'] = $val[4];
            $data[$num]['number'] = $val[5];
            $data[$num]['remark'] = $val[6];
            $data[$num]['xmcm'] = $val[7];
            $data[$num]['xfcm_qcy'] = $val[8];
            $data[$num]['xfcm_hzy'] = $val[9];
            $data[$num]['xfcm_jxw'] = $val[10];
            $data[$num]['xfcm_cyxw'] = $val[11];
            $data[$num]['xfcm_zy'] = $val[12];
            $data[$num]['xfcm_yw'] = $val[13];
            $data[$num]['xfcm_jk'] = $val[14];
            $data[$num]['xfcm_xc'] = $val[15];
            $data[$num]['xkcm'] = $val[16];
            $data[$num]['xkcm_jyw'] = $val[17];
            $data[$num]['xkcm_cyyw'] = $val[18];
            $data[$num]['xkcm_jtw'] = $val[19];
            $data[$num]['xkcm_cytw'] = $val[20];
            $data[$num]['xkcm_hd'] = $val[21];
            $data[$num]['xkcm_qkc'] = $val[22];
            $num++;
        }
        unlink($path);
        $data_cc['code'] = 200;
        $data_cc['msg'] = '导入成功';
        $data_cc = $data;
        exit(json_encode($data_cc));
    }

    //导出
    public function data_export()
    {
        $detail = I('');
        $order_id = $detail['order_id'];
        $company_id = $detail['company_id'];
        $department_id = $detail['department_id'];
        if (empty($order_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '订单ID不能为空';
            exit(json_encode($data_cc));
        }
        if (empty($company_id)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = '企业ID不能为空';
            exit(json_encode($data_cc));
        }

        $uo_model = M("user_order");
        $where['uid'] = UID;
        $where['id'] = $order_id;
        $where['isdel'] = 0;
        $info = $uo_model->where($where)->find();
        if (empty($info)) {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "信息查询失败";
            exit(json_encode($data_cc));
        }
        $user_tuantidingzhi = M("user_tuantidingzhi");
        $t_where['order_id'] = $order_id;
        $t_where['uid'] = UID;
        $t_where['comp_id'] = $company_id;
        $t_where['isdel'] = 0;
        if ($department_id) {
            $t_where['part_id'] = $department_id;
        }
        $list = $user_tuantidingzhi->where($t_where)->order('id asc')->select();
        foreach ($list as $key => $val) {
            //客户信息
            $data[$key][] = $val['names'];
            $data[$key][] = $val['age'];
            $data[$key][] = $val['sex'] == 1 ? '男' : '女';
            $data[$key][] = $val['height'];
            $data[$key][] = $val['weight'];
            $data[$key][] = $val['number'];
            $data[$key][] = $val['remark'];
            //上装
            $data[$key][] = $val['xmcm'];//西服尺寸
            $data[$key][] = $val['linwei'];//领围
            $data[$key][] = $val['xfcm_qcy'];//西服尺码-前长衣
            $data[$key][] = $val['xfcm_hzy'];//西服尺码-后中衣
            //$data[$key][] = $val['xfcm_jxw'];//西服尺码-净胸围
            $data[$key][] = $val['xfcm_cyxw'];//西服尺码-成衣胸围
            $data[$key][] = $val['xfcm_zy'];//中腰
            $data[$key][] = $val['xfcm_yw'];//西服尺码-成衣腰围
            $data[$key][] = $val['xfcm_jk'];//西服尺码-肩宽
            $data[$key][] = $val['xfcm_xc'];//西服尺码-袖长
            $data[$key][] = $val['xiuwei'];//西服尺码-袖围
            $data[$key][] = $val['xiabai'];//西服尺码-下摆

            //下装
            $data[$key][] = $val['xkcm'];//西裤尺码
            // $data[$key][] = $val['xkcm_jyw'];
            $data[$key][] = $val['xkcm_cyyw'];//西裤尺码-成品腰围
            // $data[$key][] = $val['xkcm_jtw'];
            $data[$key][] = $val['xkcm_cytw'];//西裤尺码-成品臀围
            $data[$key][] = $val['tuiwei'];//西裤尺码-腿围
            $data[$key][] = $val['xkcm_hd'];//西裤尺码-横档
            $data[$key][] = $val['xkcm_qkc'];//西裤尺码-裙/裤长
            $data[$key][] = $val['jiaokou'];//西裤尺码-脚口
        }

        $data_field[] = '顾客姓名';
        $data_field[] = '年龄';
        $data_field[] = '性别';
        $data_field[] = '身高';
        $data_field[] = '体重(斤)';
        $data_field[] = '数量';
        $data_field[] = '备注';
        $data_field[] = '西服尺寸';
        $data_field[] = '领围';
        $data_field[] = '前衣长';
        $data_field[] = '后中长';
        // $data_field[] = '净胸围';
        $data_field[] = '成衣胸围';
        $data_field[] = '中腰';
        $data_field[] = '成衣腰围';
        $data_field[] = '肩宽';
        $data_field[] = '袖长';
        $data_field[] = '袖围';
        $data_field[] = '下摆';
        $data_field[] = '西裤尺寸';
        // $data_field[] = '裤净腰围';
        $data_field[] = '成品腰围';
        // $data_field[] = '净臀围';
        $data_field[] = '成衣臀围';
        $data_field[] = '腿围';
        $data_field[] = '横档';
        $data_field[] = '裙/裤长';
        $data_field[] = '脚口';
        $str = '团体定制模板';
        $xlsCell = $data_field;
        tuan_exportExcel($str, $xlsCell, $data);
    }
}